package com.macro.mall.controller;

import com.macro.mall.common.api.CommonResult;
import com.macro.mall.dto.Goods;
import com.macro.mall.service.GoodsService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @Author：尚志豪
 * @Package：com.macro.mall.portal.controller
 * @Project：mall-swarm-B
 * @name：AddressController
 * @Date：2024/10/31 11:30
 */
@Controller
@Tag(name = "GoodsController", description = "商品增删改查")
@RequestMapping("/goods")
public class GoodsController {

    @Autowired
    private GoodsService goodsService;
//    @Autowired
//    private FastFileStorageClient storageClient;

    /**
     * 列表
     */
    @PostMapping("/list")
    public CommonResult<List<Goods>> list(){
        List<Goods> list = goodsService.list();
        return CommonResult.success(list);
    }
    /**
     * 回显
     */
    @PostMapping("/getList")
    public CommonResult<Goods> getList(@RequestParam Integer id){
        Goods goods = goodsService.getList(id);
        return CommonResult.success(goods);
    }

    /**
     * 添加
     */
    @PostMapping("/add")
    public CommonResult add(@RequestBody Goods goods){
        goodsService.add(goods);
        return CommonResult.success("添加成功");
    }
    /**
     * 删除
     */
    @PostMapping("/del")
    public CommonResult del(Integer id){
        goodsService.del(id);
        return CommonResult.success("删除成功");
    }
    /**
     * 修改
     */
    @PostMapping("/update")
    public CommonResult update(@RequestBody Goods goods){
        goodsService.update(goods);
        return CommonResult.success("修改成功");
    }

    /**
     * 图片
     */
//    @PostMapping("/upload")
//    public CommonResult upload(MultipartFile file){
//        try {
//            String originalFilename = file.getOriginalFilename();//获得文件的真实名称
//            String[] split = originalFilename.split("\\.");
//            StorePath storePath = storageClient.uploadFile(
//                    file.getInputStream(), file.getSize(), split[1], null
//            );
//            return CommonResult.success("http://150.158.86.96:8888/"+storePath.getFullPath());
//        } catch (IOException e) {
//
//        }
//        return CommonResult.failed();
//    }


}
